package cn.charlotte.pit.commands.admin;

import cn.charlotte.pit.ThePit;
import cn.charlotte.pit.commands.PitCommands;
import cn.charlotte.pit.config.PitConfig;
import cn.charlotte.pit.runnable.RebootRunnable;
import cn.charlotte.pit.util.chat.CC;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import org.bukkit.entity.Player;

@CommandAlias("pitdebug")
@CommandPermission("pit.admin")
public class Debug extends BaseCommand {
    private final PitCommands pitCommands;

    public Debug(PitCommands pitCommands) {
        this.pitCommands = pitCommands;
    }


    @Default
    @CommandCompletion("infNpc|toggle|enchNpc|toPublic|toPrivate")
    public void setDebugNpcs(Player player, String value) {
        final PitConfig pitConfig = ThePit.getInstance().getPitConfig();
        if (value.equals("infNpc")) {
            pitConfig.setInfinityNpcLocation(player.getLocation());
            pitConfig.save();

            player.sendMessage(CC.translate("&aOK!"));
        }

        if (value.equalsIgnoreCase("toggle")) {
            pitConfig.setDebugServer(!pitConfig.isDebugServer());
            pitConfig.save();

            if (pitConfig.isDebugServer()) {
                player.sendMessage(CC.translate("&a现在开启了，重启以生效"));
            } else {
                player.sendMessage(CC.translate("&c现在关闭了，重启以生效"));
            }
            ThePit.getInstance().getRebootRunnable()
                    .addRebootTask(new RebootRunnable.RebootTask("服务器配置切换", System.currentTimeMillis() + 10 * 1000));
        }

        if (value.equals("enchNpc")) {
            pitConfig.setEnchantNpcLocation(player.getLocation());
            pitConfig.save();

            player.sendMessage(CC.translate("&aOK!"));
        }

        if (value.equals("toPublic")) {
            pitConfig.setDebugServerPublic(true);
            pitConfig.save();

            player.sendMessage(CC.translate("&a现在开启了"));
        }

        if (value.equals("toPrivate")) {
            pitConfig.setDebugServerPublic(false);
            pitConfig.save();

            player.sendMessage(CC.translate("&c现在关闭了"));
        }
    }
}
